package com.example.demo;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RabbitMqUtils {

    private static final String HOST = "114.55.90.67"; // RabbitMQ 服务器地址
    private static final int PORT = 5672;           // RabbitMQ 服务器端口
    private static final String USERNAME = "admin"; // 用户名
    private static final String PASSWORD = "0pgEyAHAols6X5tcG63b"; // 密码

    private static Connection connection;

    static {
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(HOST);
            factory.setPort(PORT);
            factory.setUsername(USERNAME);
            factory.setPassword(PASSWORD);
            connection = factory.newConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取 RabbitMQ 通道
     *
     * @return Channel 实例
     * @throws Exception 如果获取通道失败
     */
    public static Channel getChannel() throws Exception {
        return connection.createChannel();
    }
}
